//
//  CarFooterCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/21/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit


final class CarFooterCell: UITableViewCell, ConfigurableCell, MainVCCell {

    // MARK: - Outlets

    private lazy var callBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("Позвонить", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
        btn.setTitleColor(.white, for: .normal)
        
        btn.backgroundColor = .rgb(60, 72, 88)
        btn.layer.cornerRadius = 15
        return btn
    }()
    
    private lazy var chatIconBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "message"), for: .normal)
        btn.backgroundColor = .rgb(60, 72, 88)
        btn.layer.cornerRadius = 15
        return btn
    }()
    
    // MARK: - Props
    
    var delegate: MainVCCellActionsDelegate!
    
    enum FooterContact {
        case chat, call
    }
    
    
    // MARK: - Actions
    
    @objc private func onCall (sender: UIButton) {
        delegate.contactSeller(type: .call)
    }
    
    @objc private func onMessage (sender: UIButton) {
        delegate.contactSeller(type: .chat)
    }
    
    // MARK: - Init
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addViews()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configure(data object: MainViewModel.CarFooterContacts?, index: Int) {}

    func returnData() -> MainViewModel.CarFooterContacts? { return nil }
    
    
    private func addViews () {
        self.contentView.addSubview(callBtn)
        self.contentView.addSubview(chatIconBtn)
        self.contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        
        
        chatIconBtn.addTarget(self, action: #selector(self.onMessage(sender:)), for: .touchUpInside)
        callBtn.addTarget(self, action: #selector(self.onCall(sender:)), for: .touchUpInside)
        
        chatIconBtn.snp.makeConstraints { (make) in
            make.height.equalTo(44)
            make.trailing.equalToSuperview().inset(16)
            make.top.equalToSuperview().inset(44)
            make.bottom.equalToSuperview().offset(-30)
            make.width.equalTo(120)
        }
        
        callBtn.snp.makeConstraints { (make) in
            make.leading.equalToSuperview().inset(16)
            make.height.equalTo(44)
            make.trailing.equalTo(chatIconBtn.snp.leading).offset(-5)
            make.top.bottom.equalTo(chatIconBtn)
        }
    }
    
}
